//
//  YHYCompanyAddPictureCell.m
//  Home
//
//  Created by 杨泓晔 on 16/6/23.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYActivityPictureTableViewCell.h"

@interface YHYActivityPictureTableViewCell ()

@end


@implementation YHYActivityPictureTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        [self createSubView];
       
//       
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    
    return self;
}

-(void)addUIVeiw{

    NSLog(@"jjjjjj=%@",self.imageArray);
    for (int i = 0; i < self.imageArray.count; i ++) {
        
        self.placeImageButton = [UIButton buttonWithType: UIButtonTypeCustom];
//        self.placeImageButton.backgroundColor = [UIColor redColor];
        self.placeImageButton.tag = 1000 + i;
        [self.placeImageButton addTarget:self action:@selector(addImages:) forControlEvents:UIControlEventTouchUpInside];
        [self.placeImageButton setImage:self.imageArray[i] forState:UIControlStateNormal];
        [self addSubview:self.placeImageButton];
        [self.placeImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(self).offset(11);
            make.top.equalTo(self).offset(11);
            make.size.mas_equalTo(CGSizeMake(80, 80));
            
        }];
        
        
    }
    


}

- (CGFloat)imageCellHeight:(CGFloat)images{
 
    
    return  120;
}



- (void)createSubView {
    self.backView = [UIView new];
    [self addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self);
        make.height.mas_equalTo(self);
        make.width.mas_equalTo(self);
    }];
    self.backView.backgroundColor = LV;
    // self.backView.backgroundColor = [UIColor redColor];
    
    
    
    _myImageView = [UIImageView new];
    [self.backView addSubview:_myImageView];
    [_myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.width.mas_equalTo(_backView);
        make.height.mas_equalTo(580/ 3 * AUTO_HEIGHT);
        
    }];
    _myImageView.backgroundColor = [UIColor whiteColor];
    
    
    
    UIImageView *imageView = [UIImageView new];
    [self.backView addSubview:imageView];
    imageView.image = [UIImage imageNamed:@"虚线"];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.7 * AUTO_HEIGHT);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(self.backView);
        make.top.mas_equalTo(580 / 3 * AUTO_HEIGHT);
        
    }];
    
    _deleteButton = [UIButton new];
    [self.backView addSubview:_deleteButton];
    [_deleteButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView.mas_bottom);
        make.left.mas_equalTo(self.backView);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
        make.height.mas_equalTo(120 /3 * AUTO_HEIGHT);
        
    }];
    _deleteButton.tag = 1000;
    _deleteButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:TEXTCONTENTFONT * TEXTWEIGHT];
    [_deleteButton addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
    _deleteButton.backgroundColor = [UIColor whiteColor];
    
    
    UIImageView *ine1 = [UIImageView new];
    [self.backView addSubview:ine1];
    ine1.image = [UIImage imageNamed:@"虚线竖"];
    [ine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_deleteButton.mas_top).offset(8 * AUTO_HEIGHT);;
        
        make.width.mas_equalTo(.7 * AUTO_WIDTH);
        make.bottom.mas_equalTo(self.backView.mas_bottom).offset(- 8 * AUTO_HEIGHT);
        make.left.mas_equalTo(_deleteButton.mas_right);
        
    }];
    
    
    _moveUPButton = [UIButton new];
    [self.backView addSubview:_moveUPButton];
    [_moveUPButton setTitleColor:GH forState:UIControlStateNormal];
    [_moveUPButton setTitle:@"上移" forState:UIControlStateNormal];
    [_moveUPButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView.mas_bottom);
        make.left.mas_equalTo(_deleteButton.mas_right);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
        make.height.mas_equalTo(120 /3 * AUTO_HEIGHT);
        
    }];
    _moveUPButton.tag = 1001;
    _moveUPButton.backgroundColor = [UIColor whiteColor];
    _moveUPButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:TEXTCONTENTFONT * TEXTWEIGHT];
    [_moveUPButton addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UIImageView *ine2 = [UIImageView new];
    [self.backView addSubview:ine2];
    ine2.image = [UIImage imageNamed:@"虚线竖"];
    [ine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_deleteButton.mas_top).offset(8 * AUTO_HEIGHT);;
        
        make.width.mas_equalTo(.7 * AUTO_WIDTH);
        make.bottom.mas_equalTo(self.backView.mas_bottom).offset(- 8 * AUTO_HEIGHT);
        make.left.mas_equalTo(_moveUPButton.mas_right);
        
    }];
    
    
    
    
    
    
    _downButton = [UIButton new];
    [self.backView addSubview:_downButton];
    [_downButton setTitleColor:GH forState:UIControlStateNormal];
    [_downButton setTitle:@"下移" forState:UIControlStateNormal];
    [_downButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView.mas_bottom);
        make.left.mas_equalTo(_moveUPButton.mas_right);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
        make.height.mas_equalTo(120 /3 * AUTO_HEIGHT);
        
    }];
    _downButton.tag = 1002;
    _downButton.backgroundColor = [UIColor whiteColor];
    _downButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:TEXTCONTENTFONT * TEXTWEIGHT];
    [_downButton addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
//    UIImageView *ine3 = [UIImageView new];
//    [self.backView addSubview:ine3];
//    ine3.image = [UIImage imageNamed:@"虚线竖"];
//    [ine3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(_deleteButton.mas_top).offset(8 * AUTO_HEIGHT);;
//        
//        make.width.mas_equalTo(.7 * AUTO_WIDTH);
//        make.bottom.mas_equalTo(- 8 * AUTO_HEIGHT);
//        make.left.mas_equalTo(_downButton.mas_right);
//        
//    }];
//
//    
//    
//    _editButton = [UIButton new];
//    _editButton.backgroundColor = [UIColor whiteColor];
//    [self.backView addSubview:_editButton];
//    [_editButton setTitleColor:GH forState:UIControlStateNormal];
//    [_editButton setTitle:@"编辑" forState:UIControlStateNormal];
//    [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(imageView.mas_bottom);
//        make.left.mas_equalTo(_downButton.mas_right);
//        make.width.mas_equalTo(SCREEN_WIDTH/4);
//        make.height.mas_equalTo(120 /3 * AUTO_HEIGHT);
//        
//    }];
//    _editButton.tag = 1003;
//    _editButton.backgroundColor = [UIColor whiteColor];
//    _editButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:TEXTCONTENTFONT * TEXTWEIGHT];
//    [_editButton addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _myLabel = [UILabel new];
    [self addSubview:_myLabel];
    [_myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_downButton.mas_bottom).offset(10);
        make.height.mas_equalTo(15 * AUTO_HEIGHT);
        make.left.mas_equalTo(self.backView).offset(20 * AUTO_WIDTH);
        make.right.mas_equalTo(self.backView.mas_right).offset(- 20 * AUTO_WIDTH);
        
    }];
    _myLabel.textColor = ZI;
    _myLabel.font = [UIFont fontWithName:@"Arial" size:TEXTNAMEFONT];
//    _myLabel.backgroundColor = [UIColor redColor];
    
    _myLabel.lineBreakMode = NSLineBreakByCharWrapping;
       
}

//- (void)setMyImageView:(UIImageView *)myImageView{
//
//
//     _myImageView = myImageView;
//  //  [self imageCompressForSize:_myImageView.image targetSize:CGSizeMake(SCREEN_WIDTH, 150/3 * AUTO_HEIGHT)];
//}

- (void)setMyLabel:(UILabel *)myLabel{
    if (_myLabel != myLabel) {

        
        CGFloat textHeight = [self heightForContent:myLabel.text width:365.0 font:14];
        CGRect textFrame = myLabel.frame;
        textFrame.size.height = textHeight;
        self.myLabel.frame = textFrame;

      
//        [_myLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//            
//            make.top.mas_equalTo(_downButton.mas_bottom).offset(15 * AUTO_HEIGHT);
//            make.height.mas_equalTo(textHeight* AUTO_HEIGHT);
//            make.left.mas_equalTo(self.backView).offset(20 * AUTO_WIDTH);
//            make.right.mas_equalTo(self.backView.mas_right).offset(- 20 * AUTO_WIDTH);
//        }];
        
//     _myLabel.numberOfLines = 30;
        
        

        
    
    
     
   
   
    self.myLabel.numberOfLines = 0;
    
    //wenzi
#pragma mark 文字适应高度
    //********* 字体默认的也要调动一下
    self.myLabel.font = [UIFont systemFontOfSize:14];
    //textLabel的高度
    //    CGFloat textHeight = [self heightForContent:self.firstTabBarModel.content width:365.0 font:14];
    //    CGRect textFrame = self.self.labelContent.frame;
    //    textFrame.size.height = textHeight;
    //    self.labelContent.frame = textFrame;
    //    [self.scrollView addSubview:self.labelContent];
    //    NSLog(@"%f",textHeight);//?????????????
#pragma mark - 数组添加图片

    
    }
    
}


//文字是配

+ (CGFloat)heightForContent:(NSString *)content
{
    //参数1.设置计算高度按照什么样的size来计算
    //注意: 宽度一定与Label宽度一致，高度尽量大一点
    CGSize size = CGSizeMake(300, 10000);
    //参数2.设置计算类型
    //参数3.设置计算内容按照多大字体计算
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0], NSFontAttributeName, nil];
    //注意: 字体大小也要跟Label字体一样
    //参数4.系统备用参数，设置为nil
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    
    return frame.size.height;
}

- (void)setMyImageView:(UIImageView *)myImageView{
    _myImageView = myImageView;
}

- (CGFloat)heightForContent:(NSString *)content width:(NSInteger)kuan font:(CGFloat)font{
    
    
    CGSize size = CGSizeMake(kuan, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font], NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}



- (void)Action:(UIButton *)btu{
    [self.delegate buttonAction:btu];
}


-(void)addImages:(UIButton *)images{

    
    [self.delegate buttonAction:images];

}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
